<?php
/**
 * Created by Zhy
 * User: Zhy
 * Date: 2023/8/11
 * Time: 14:47
 */

namespace app\admin\controller;

use think\Db;
use think\Request;

class Rechargeproject extends Base
{
    /**
     * 充值项目
     * @return mixed|\think\response\Json
     */
    public function index(){
        if(request()->isAjax ()){
            $Nowpage = input('page') ? input('page') : 1;
            $limits = input("limit") ? input("limit") : 50;
            $count = Db::name('bo_in')->where('status', 1)->count();// 获取总条数
            $lists = Db::name('bo_in')
                ->where('status', 1)
                ->field('id, name, desc')
                ->page($Nowpage,$limits)
                ->order('id asc')
                ->select();

            return json(['code' => 220, 'msg' => '', 'count' => $count, 'data' => $lists]);
        }
        return $this->fetch();
    }

    /**
     * 编辑
     * @return mixed|\think\response\Json
     */
    public function projectEdit(){
        $id = input('id');
        if(Request::instance()->isPost()){
            $desc = trim(input('desc'), ' ');
            $res = Db::table('up_bo_in')->where('id', $id)
                ->update(['desc' => $desc, 'update_time' => date('Y-m-d H:i:s')]);
            if($res){
                return json(['code' => 200, 'msg' => '编辑成功']);
            }else{
                return json(['code' => 100, 'msg' => '编辑失败']);
            }
        }
        $d = Db::table('up_bo_in')->where('id', $id)->where('status', 1)->field('desc, name')->find();
        return $this->fetch('', ['d' => $d, 'id' => $id]);
    }
}